const app = getApp()
import Toast from '@vant/weapp/toast/toast'
import Dialog from '@vant/weapp/dialog/dialog';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userinfo:null,
    isxuzhi:false
  },
  getconfirm(){
    this.setData({
      isxuzhi:false
    })
  },
  
  getLogin(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  avatarHeld(){
    if(wx.getStorageSync('token')){
      wx.navigateTo({
        url: '/pages/avatar/avatar?userinfo='+ JSON.stringify(this.data.userinfo),
      })
    }else{
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  },
  skipPhotograph(){
    if(wx.getStorageSync('token')){
      wx.navigateTo({
        url: '/pages/report/report?userinfo='+ JSON.stringify(this.data.userinfo),
      })
    }else{
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  
},
skipAward(){
  if(wx.getStorageSync('token')){
    wx.navigateTo({
      url: '/pages/award/award',
    })
  }else{
    wx.navigateTo({
      url: '/pages/login/login',
    })
  }
  
},
skipBonus(){
  if(wx.getStorageSync('token')){
    wx.navigateTo({
      url: '/pages/bonus/bonus',
    })
    
  }else{
    wx.navigateTo({
      url: '/pages/login/login',
    })
  }
  
},
skipRulegz(){
  wx.navigateTo({
    url: '/pages/rulegz/rulegz',
  })
},
serviceHeld(){
  Toast('请联系客服！')
},
getusers(){
  let that = this
  app.globalData.header.Authorization = wx.getStorageSync('token')
  wx.request({
    url: app.serverUrl + '/api/user',
    header:app.globalData.header,
    method: 'GET',
    success:res=>{
      if(res.data.code==200){
        if(res.data.data.avatar==''){
          res.data.data.avatarIY=""
        }else{
          res.data.data.avatarIY = app.serverUrl+'/storage/'+res.data.data.avatar
        }
        that.setData({
          userinfo:res.data.data
        })
      }
    }
  })
},
outHeld(){
  Dialog.confirm({
    title: '提示',
    message: '确定退出当前登录？',
  })
    .then(() => {
      wx.clearStorage()
      setTimeout(()=>{
        wx.reLaunch({
          url: '/pages/index/index',
        })
      },200)
    })
    .catch(() => {
    });
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      isxuzhi:true
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if(wx.getStorageSync('token')){
      this.getusers()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    if(wx.getStorageSync('token')){
      this.getusers()
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})